package com.utonw.carloan.adpter.applyloan;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.utonw.carloan.fragment.BaseFragment;
import com.utonw.carloan.fragment.applyloan.LoanStepSevenFragment;
import com.utonw.carloan.fragment.applyloan.LoanStepSixFragment;

import java.util.ArrayList;

/**
 * Created by SEELE on 2017/3/22.
 */

public class ApplyLoanAdapter extends FragmentPagerAdapter {

    private ArrayList<Fragment> mData;
    private BaseFragment currentFragment;

    public void setData(ArrayList<Fragment> data) {
        mData = data;
        notifyDataSetChanged();
    }

    public ApplyLoanAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return mData.get(position);
    }

    @Override
    public int getCount() {
        return mData != null && mData.size() != 0 ? mData.size() : 0;
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        super.setPrimaryItem(container, position, object);
        currentFragment = (BaseFragment) object;
    }

    public BaseFragment getCurrentFragment() {
        return currentFragment;
    }

    //获取Fragment 7中的联系人集合
    public LoanStepSevenFragment getAllContract() {
        return mData != null ? (LoanStepSevenFragment) mData.get(5) : null;
    }

    //获取是否有信用卡
    public LoanStepSixFragment hasCreditCard() {
        return mData != null ? (LoanStepSixFragment) mData.get(4) : null;
    }
}
